package com.smart_campus.bus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.bus.domain.Journal;
import com.smart_campus.bus.domain.ModelType;
import com.smart_campus.bus.mapper.JournalMapper;
import com.smart_campus.bus.service.JournalService;

import com.smart_campus.bus.vo.JournalVo;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.common.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author saoji
 * @since 2020-06-07
 */
@Service
public class JournalServiceImpl implements JournalService {

    @Autowired
    private JournalMapper journalMapper;

    /**
     * 条件查询
     * */
    @Override
    public List<Journal> getJournal(Integer page, Integer limit, String type,String keyWords) {
        if(page!=null && limit!=null){
            return journalMapper.getJournal((page-1)*limit,limit,type,keyWords);
        }else {
            return journalMapper.getJournal(page,limit,type,keyWords);
        }
    }

    @Override
    public List<ModelType> getAllModelType() {
        return journalMapper.getAllModelType();
    }

    @Override
    public List<Journal> getDataByModel(Integer page, Integer limit, String model) {
        if (page == null&& limit==null) {
            return journalMapper.getDataByModel(page,limit,model);
        }else {
            return journalMapper.getDataByModel((page-1)*limit,limit,model);
        }
    }

    @Override
    public List<Journal> getHotNews() {
        return journalMapper.getHotNews();
    }

    /**
     * 根据id查询
     * */
    @Override
    public Journal getDataById(int id) {
        return journalMapper.getDataById(id);
    }

    /**
     * 添加
     * */
    @Override
    public Boolean addJournal(Journal journal) {
        return journalMapper.addJournal(journal);
    }

    /**
     * 修改
     * */
    @Override
    public Boolean updateJournal(Journal journal) {
        return journalMapper.updateJournal(journal);
    }

    /**
     * 删除
     * */
    @Override
    public Boolean removeJournal(int id) {
        return journalMapper.removeJournal(id);
    }

    @Override
    public DataGridView selallJournal(JournalVo vo) {
        Page<Object> page = PageHelper.startPage(vo.getPage(),vo.getLimit());
        List<Journal> list = journalMapper.selallJournal(vo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public Boolean addReadCount(Journal journal) {
        return journalMapper.addReadCount(journal);
    }

    @Override
    public Boolean addCommentCount(Journal journal) {
        return journalMapper.addCommentCount(journal);
    }
}
